<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-30">
			<view class="margin-30-0 flex-around" @click="$tools.navigateBack()">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">{{store_name}}</view>
				<view style="width: 40rpx;"></view>
			</view>
			
			<!-- 列表 -->
			<view class="border-radius20 bg-fff margin-bottom30"
			v-for="(item,index) in list" :key="index"
			 style="overflow: hidden;box-shadow: 2px 2px 2px #cccccc;"
			@click="goToDetail1(item)">
				<image class="img-list" :src="item.image" mode=""></image>
				<view class="flex-between padding-30">
					<view class="fontSize-15 color-704234">{{item.title}}</view>
					<view class="fontSize-15 color-704234">￥{{item.price}}</view>
				</view>
			</view>
			
			<u-empty v-if="list.length == 0"
			        mode="list"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
					width="150px"
					height="150px"
					text="列表为空"
					textSize="18"
			>
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
				store_id:'',
				store_name:''
			}
		},
		onLoad(e) {
			this.store_id = e.store_id
			this.store_name = e.store_name
			// this.$tools.setNavigationBarTitle(this.store_name)
			console.log(e)
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getGoodsList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getGoodsList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getGoodsList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			// 跳转
			goToDetail1(item){
				this.$tools.navigateTo('/pages/auspiciousness/taoist-goods-info?goods_id='+item.id+'&pathCode='+'祈福')
			},
			// 获取商品列表
			async getGoodsList(){
				let form = {
					page:this.page,
					limit:this.limit,
					store_id:this.store_id,
					goods_type:4,
				}
				this.$http.post(this.$api.goods_list,form,{token:true}).then(res => {
					this.list = [...this.list,...res.data]
				}).finally(() => {
					// 停止当前页面下拉刷新
					uni.stopPullDownRefresh();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.img-list{
		width: 100%;
		height: 320rpx;
		flex-shrink: 0;
		border-radius: 20;
		// border: 2px solid  #967C5E;
	}
	.header-bg-image {
		width: 100%;
		min-height: 100vh;
	}
</style>